<template>
   <div>
    <el-table
      :data="tableData"
      style="width: 100%"
      border
    >
      <el-table-column type="index" label="#" width="50" />
      <el-table-column prop="userName" label="昵称" width="150" show-overflow-tooltip />
      <el-table-column prop="date" label="头像" width="180">
        <template #default="scope">
          <img class="header-img" :src="scope.row.headImg" alt="">
        </template>
      </el-table-column>
      <el-table-column prop="motto" label="座右铭" width="180" show-overflow-tooltip />
      <el-table-column label="作业地址">
        <template #default="scope">
          <a :href="scope.row.workUrl" target="_blank" >{{ scope.row.workUrl }}</a>
        </template>
      </el-table-column>
      <el-table-column prop="ip" label="ip地址" />
      <el-table-column  label="状态" >
        <template #default="scope">
           <el-tag v-if="userIsLineIds.includes(scope.row.userId)" type="primary">在线</el-tag>
           <el-tag v-else type="info">离线</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <pageBox :total="totalNum" :pageData="pageData" @pageSizeChange="pageSizeChange" @pageChange="pageChange" />
   </div>
</template>

<script lang="ts">
import { getPageData } from '@/api/userInfo'
import pageBox from '@/components/pageBox.vue'
import { userStatusList } from '@/socket/'
export default {
  components: {
    pageBox
  },
  data() {
    return {
      userStatusList,
      tableData: [],
      totalNum: 0,
      pageData: {
        page: 1,
        pageSize: 10
      }
    }
  },
  computed: {
    userIsLineIds() {
      return this.userStatusList.map(item => item.userId);
    }
  },

  created() {
    this.getData()
  },
  methods: {
    getData() {
      // 接口数据
      getPageData(this.pageData).then(res => {
        this.tableData = res.data.rows;
        this.totalNum = res.data.total
      })
    },
    pageSizeChange(pageSize: number) {
      this.pageData.pageSize = pageSize
      this.pageData.page = 1;
      this.getData() // 请求数据
    },
    pageChange(page: number) {
      this.pageData.page = page
       this.getData() // 请求数据
    }
  }
}
</script>

<style lang="scss" scoped>
.header-img{
  width: 50px;
  height: 50px;
}


</style>
